<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>MCU Manager</title>
	<%@ include file="/WEB-INF/jsp/common/cssjs2.jsp" %>
	
	<script type="text/javascript">
		$(function(){
			$('.easyui-validatebox').validatebox();
			$('.easyui-validatebox[required]').after("<font color='red'> *</font>");
		});
		
		function doSubmit(){
			$('#id_form').form('submit', {
		        url:"<c:url value='/app/manage/group'/>",
		        onSubmit: function(){
		        	if($('.easyui-validatebox').validatebox("isValid")==false){
		        		return false;
		        	}else if(isNameExist()){
		        		alert(messages.getMsg("error.exist",[$("#id_name").val()]));
		        		return false;
		        	}else{
						return true;
					}
		        },
		        success:function(data){
					if("<fmt:message key="operation.success"/>" != data)
						alert(data);
					parent.ptcGroupViewObj.reload();
					parent.closeWin();
		        }
			});
		}
		
		function isNameExist(){
			var ret=false;
			var _name=$("#id_name").val();
			var _preName="<c:out value='${model.name}'/>";
			
			if("${param.opt}"=="modify"&&_name==_preName){//whether is the same name in the modify page
				ret=false;
			}else{
				$.ajax({
					url:"<c:url value='/app/manage/group/check'/>",
					async:false,
					type:"GET",
					data:{
						key:$("#id_name").val(),
						times:new Date().toString()
					},
					success:function(data){
						if(data=="true")
							ret=true;
					}
				});
			}
			
			return ret;
		}
	</script>
	
	<style type="text/css">
	    html, body {
	        width: 100%;
	        height: 100%;
	        margin: 0px;
	        overflow: hidden;
	    }
	</style>
</head>
<body class="dialog">
	<div class="table-container">
		<div style="height:20px;"></div>
		<form id="id_form" method="post">
		<c:if test="${param.opt=='modify'}">
			<input type="hidden" value="PUT" name="_method"/>
		</c:if>
		<table>
			<tr>
				<td><fmt:message key='form.participantGroup.name'/></td>
				<td><input type="text" id="id_name" <c:if test="${param.opt=='modify'}">readonly="readonly" style="background-color: #DEDBD6;"</c:if> name="name" value="<c:out value='${model.name}'/>" class="input-text easyui-validatebox" validType="nodelimiter" required="true"></td>
			</tr>
			<tr>
				<td><fmt:message key='form.participantGroup.description'/></td>
				<td><textarea rows="5" name="description" class="input-text"><c:out value='${model.description}'/></textarea></td>
			</tr>
			<tr>
				<td colspan="2">
					<p align="center">
                        <input type="button" onclick="doSubmit();" class="mybtn" value="<fmt:message key='btn.ok'/>">
						<button onclick="parent.closeWin();" class="mybtn"><fmt:message key='btn.cancel'/></button>
					</p>
				</td>
			</tr>
		</table>
		</form>
		<div style="height:20px;"></div>
	</div>
</body>
</html>